const {data} = require('./src/mock/mock')
module.exports = {
    devServer: {
        before(app) {
            app.get('/api/list', (req,res) => {
                const {tag} = req.query;
                let newData;
                // 筛选
                if(tag) {
                    newData = data.list.filter((v,i) => {
                        return v.tag*1 === tag*1
                    })
                } else {
                    newData = data.list;
                }
                
                res.json({
                    code: 1,
                    data: newData
                })
            }),
            app.get('/api/detail', (req,res) => {
                const {id} = req.query;
                let newData;
                // 筛选
                if(id) {
                    newData = data.list.filter((v,i) => {
                        return v.id*1 === id*1
                    })[0]
                }
                res.json({
                    code: 1,
                    data: newData
                })
            })
        }
    }
}